package pl.edu.pw.stud.ltrzaska.policy.xml;

import javax.xml.transform.stream.StreamSource;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
import javax.xml.validation.Validator;

import org.xml.sax.SAXException;

/**
 * Walidacja pliku XML na zgodnosc ze schematem XSD.
 */

public class Test {
	public static void main(String[] args) {
		try {
			String schemaLang = "http://www.w3.org/2001/XMLSchema";
			SchemaFactory factory = SchemaFactory.newInstance(schemaLang);
			Schema schema = factory.newSchema(new StreamSource("sample.xsd"));
			Validator validator = schema.newValidator();

			validator.validate(new StreamSource("sample.xml"));

		} catch (SAXException ex) {
			// we are here if the document is not valid:
			// ... process validation error...
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}
}